class ContractListResponse {
  final AdsContract ads;
  // final DailyContract daily;
  final List<PaidContract> list;
  final List<String> productIds;

  ContractListResponse({
    required this.ads,
    // required this.daily,
    required this.list,
    required this.productIds,
  });

  factory ContractListResponse.fromJson(Map<String, dynamic> json) {
    return ContractListResponse(
      ads: AdsContract.fromJson(json['ads']),
      // daily: DailyContract.fromJson(json['daily']),
      list: (json['list'] as List)
          .map((item) => PaidContract.fromJson(item))
          .toList(),
      productIds: List<String>.from(json['product_ids']),
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'ads': ads.toJson(),
      // 'daily': daily.toJson(),
      'list': list.map((item) => item.toJson()).toList(),
      'product_ids': productIds,
    };
  }
}

/// 广告合约模型
class AdsContract {
  final int id;
  final String title;
  final String computingPower;
  final String describe;
  final String googleGoods;
  final String appleGoods;
  final String price;

  AdsContract({
    required this.id,
    required this.title,
    required this.computingPower,
    required this.describe,
    required this.googleGoods,
    required this.appleGoods,
    required this.price,
  });

  factory AdsContract.fromJson(Map<String, dynamic> json) {
    return AdsContract(
      id: json['id'],
      title: json['title'],
      computingPower: json['computing_power'],
      describe: json['describe'],
      googleGoods: json['google_goods'],
      appleGoods: json['apple_goods'],
      price: json['price'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'title': title,
      'computing_power': computingPower,
      'describe': describe,
      'google_goods': googleGoods,
      'apple_goods': appleGoods,
      'price': price,
    };
  }
}

/// 每日签到合约模型
class DailyContract {
  final int id;
  final String title;
  final String computingPower;
  final String describe;
  final String googleGoods;
  final String appleGoods;
  final String price;
  final int isSignin;
  final int nowTime;

  DailyContract({
    required this.id,
    required this.title,
    required this.computingPower,
    required this.describe,
    required this.googleGoods,
    required this.appleGoods,
    required this.price,
    required this.isSignin,
    required this.nowTime,
  });

  factory DailyContract.fromJson(Map<String, dynamic> json) {
    return DailyContract(
      id: json['id'],
      title: json['title'],
      computingPower: json['computing_power'],
      describe: json['describe'],
      googleGoods: json['google_goods'],
      appleGoods: json['apple_goods'],
      price: json['price'],
      isSignin: json['is_signin'],
      nowTime: json['now_time'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'title': title,
      'computing_power': computingPower,
      'describe': describe,
      'google_goods': googleGoods,
      'apple_goods': appleGoods,
      'price': price,
      'is_signin': isSignin,
      'now_time': nowTime,
    };
  }

  /// 是否已签到
  bool get hasSignedIn => isSignin == 1;
}

/// 付费合约模型
class PaidContract {
  final int id;
  final String title;
  final String computingPower;
  final String describe;
  final String googleGoods;
  final String appleGoods;
  final String price;

  PaidContract({
    required this.id,
    required this.title,
    required this.computingPower,
    required this.describe,
    required this.googleGoods,
    required this.appleGoods,
    required this.price,
  });

  factory PaidContract.fromJson(Map<String, dynamic> json) {
    return PaidContract(
      id: json['id'],
      title: json['title'],
      computingPower: json['computing_power'],
      describe: json['describe'],
      googleGoods: json['google_goods'],
      appleGoods: json['apple_goods'],
      price: json['price'],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'title': title,
      'computing_power': computingPower,
      'describe': describe,
      'google_goods': googleGoods,
      'apple_goods': appleGoods,
      'price': price,
    };
  }

  /// 获取价格数值
  double get priceValue => double.tryParse(price) ?? 0.0;
  
  /// 是否免费
  bool get isFree => priceValue == 0.0;
}